package org.railage.client.beans;

import java.util.Arrays;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import org.apache.log4j.Logger;
import org.railage.common.dto.PassengerDTO;
import org.railage.server.services.PassengerService;
import org.railage.server.services.RouteService;
import org.railage.server.services.TripService;

@ManagedBean(name = "passengers")
@ViewScoped
public class PassengersBean {
	
	private static final Logger log = Logger.getLogger(PassengersBean.class);
	
	private RouteService routeService = new RouteService();
	private TripService tripService = new TripService();
	private PassengerService passengerService = new PassengerService();

	private String[] routes = null;
	private String[] trips = null;
	private List<PassengerDTO> passengers = null;
	private String selectedRoute = null;
	private String selectedTrip = null;
	
	public PassengersBean() {
		routes = routeService.getRouteNames(null);
	}
	
	public void routeChanged() {
		log.debug("Route: " + selectedRoute);
		trips = tripService.getTripIDsByRouteName(selectedRoute);
	}
	
	public void tripChanged() {
		log.debug("Trip ID: " + selectedTrip);
		passengers = Arrays.asList(passengerService.getPassengersByTrip(Integer.parseInt(selectedTrip)));
	}

	public String getSelectedRoute() {
		return selectedRoute;
	}

	public void setSelectedRoute(String selectedRoute) {
		this.selectedRoute = selectedRoute;
	}

	public String getSelectedTrip() {
		return selectedTrip;
	}

	public void setSelectedTrip(String selectedTrip) {
		this.selectedTrip = selectedTrip;
	}

	public String[] getRoutes() {
		return routes;
	}

	public String[] getTrips() {
		return trips;
	}

	public List<PassengerDTO> getPassengers() {
		return passengers;
	}

	
	
}
